﻿/// <reference path="../vsdoc/jquery-1.8.3-vsdoc.js" />
/*
** some basic functionality
*/

/* a pack of handlers to be run on any async loaded content */
var asyncHandlersForEach = [];
function HandleAllAsync()
{
    for (var i = 0; i < asyncHandlersForEach.length; i++)
    {
        asyncHandlersForEach[i](); // execute all delegates
    }
}
$(document).ready(function ()
{
    HandleAllAsync(); // on page load execute all handlers
});

/* Session Keeper */
var SessionTimerID = null;
function KeepSessionOpen()
{
    $.get(KeepSessionOpenAction, { rand: Math.random() });
    SessionTimerID = setTimeout("KeepSessionOpen()", 280000);
}

/* Assure dialogue */
$(document).ready(function ()
{
    $("BUTTON.assure, A.assure").live('click', function (e)
    {
        var result = confirm($(this).data("assuremessage"));
        if (!result) { return false; }
    });
});

/* Moving and Paging*/
$(document).ready(function ()
{
    $("BUTTON[name=anchorButton]").live('click', function (e)
    {
        e.preventDefault();
        var href = $(this).parent().attr("href");
        if (href != null && href != "")
        {
            location = href;
        }
    });
});

/* Loading message for any AJAX */
$(document).ready(function ()
{
    $("#loading").bind("ajaxSend", function (e)
    {
        if ((e.result == null || e.result)) { $(this).show(); }
    }).bind("ajaxComplete", function (e)
    {
        $(this).hide();
    });
});

/* Scroll (re)store position */
asyncHandlersForEach.push(ReSetScrolledPositions);
function ReSetScrolledPositions()
{
    $(".scroller[id]").not("#masterBody").each(function (e)
    {  // restore scrolls on page load
        this.scrollTop = $.cookie($(this).attr("id"));
    });
    $(".scroller[id]").not("#masterBody").scroll(function (e)
    { // add scroll position 'onScroll'
        $.cookie($(this).attr("id"), this.scrollTop, { expires: 7, path: "/" });
    });
}

/* Fix for IE: when accessKey is used, IE gets the focus to anchor or button - only.
This should trigger the intended navigation (i.e. anchor or button click behaviour) */
$(document).ready(function ()
{
    $("A[accesskey]").live('focus', function (e)
    {
        e = window.event || e;
        if (e.altKey)
        {
            var message = $(this).data("assuremessage");
            if (message == null || message.length == 0 || confirm(message))
            {
                $(this).blur(); // browser back button - fix
                location = $(this).attr("href");
            }
        }
        return false;
    });
});

// append JQuery style which is not CSS VALID ... included only by JS if JS is enabled
//AppendHeadStyle('css/jquery-ui.css'); // see Culture-Settings

function AppendHeadStyle(href)
{
    var $ = this.jQuery, settings = this.settings, communityWidget = this;
    document.write(unescape("%3Clink href='" + href + "' rel='stylesheet' type='text/css' /%3E"));
}
function AppendHeadScript(href)
{
    var $ = this.jQuery, settings = this.settings, communityWidget = this;
    return document.write(unescape("%3Cscript src='" + href + "' type='text/javascript'%3E%3C/script%3E"));
}